<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/layui/css/public.css" media="all" />
    <script type="text/javascript" src="/plugins/layui/layui.js"></script>
    <title>交易对编辑</title>
    <style>
        .layui-form-label {
            width: 10%;
        }
        .layui-input-block {
            margin-left: 13%;
        }
        .required-field {
            color: red;
            margin-right: 2px;
            font-size: 15px;
            text-align: center;
        }
        img {
            width: 110px;
            height: 110px;
        }
        .layui-upload-list {
            margin-left: 13%;
        }
    </style>
</head>
<body style="margin: 15px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>交易对编辑(<label class="layui-required-tip">标红的为必填项</label>)</legend>
</fieldset>
<form class="layui-form" id="layui-form" action="" method="post">
    <div class="layui-form-item" style="display: none;">
        <label class="layui-form-label layui-required-tip" style="width: 10%;">ID：</label>
        <div class="layui-input-block">
            <input type="text" id="id" name="id" lay-verify="required"
                   autocomplete="off" class="layui-input" value="${tra.id!}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-required-tip" style="width: 10%;">币种名称：</label>
        <div class="layui-input-block">
            <select  lay-search name="transactionName" id="transactionName" lay-verify="required">
                <option value="">币种名称</option>
                <#if infos ??>
                    <#list infos as info>
                        <#if (tra ??) && (tra.transactionName == info.symbol)>
                                <option value="${info.symbol!}" selected >${info.symbol!}</option>
                            <#else>
                                <option value="${info.symbol!}" >${info.symbol!}</option>
                        </#if>
                    </#list>
                </#if>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-required-tip" style="width: 10%;">法币名称：</label>
        <div class="layui-input-block">
            <select  lay-search name="enName" id="enName" lay-verify="required">
                <option value="">法币名称</option>
                <#if enNames ??>
                    <#list enNames as en>
                        <#if (tra ??) && (tra.enName == en.symbol)>
                                <option value="${en.symbol!}" selected>${en.symbol!}</option>
                            <#else>
                                <option value="${en.symbol!}" >${en.symbol!}</option>
                        </#if>
                    </#list>
                </#if>
            </select>
        </div>
    </div>
<!--    <div class="layui-form-item">
        <label class="layui-form-label layui-required-tip">图标：</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test">
                <i class="layui-icon">&#xe67c;</i>图标
            </button>
        </div>
        <div class="layui-upload-list">
            <#if (tra.imageUrl)??>
                    <img class="layui-upload-img" id="logoImg" src="${tra.imageUrl!}" >
                <#else>
                    <img class="layui-upload-img" id="logoImg">
            </#if>
            <input type="hidden"  name="imageUrl" id="imageUrl" value="${tra.imageUrl!}" />
            <p id="logoText"></p>
        </div>
    </div>-->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="save">立即提交</button>
            <a class="layui-btn" href="/manage/trading/trapage">返回</a>
        </div>
    </div>
</form>
<script type="text/javascript" src="/js/global-config.js"></script>
<script>

    layui.config({
        base: '/js/' //假设这是你存放拓展模块的根目录
    }).extend({ //设定模块别名
        mymod: 'selectMultiple' //如果 mymod.js 是在根目录，也可以不用设定别名
    });

    layui.use(['jquery','form','upload','selectMultiple'],function(){
        var $=layui.jquery,form=layui.selectMultiple,upload = layui.upload;
        var $layer = $('#layui-form');
        form.render();
        var uploadlogo = upload.render({
            url: '/manage/upload/uploadFile?dir=tra',
            elem: '#test', //指定原始元素，默认直接查找class="layui-upload-file"
            size: 1000,
            before: function(obj) {
                layer.load();
            },
            done: function(res){
                //上传完毕回调
                $('#logoImg').attr('src', res.data); //图片链接（base64）
                $('#imageUrl').val(res.data);
                layer.closeAll('loading');
            }
            ,error: function(){
                //请求异常回调
            }
        });

        //监听提交监听提交
        form.on('submit(save)', function(data){
/*            if($("#imageUrl").val()==""){
                layer.msg("请上传图片", { icon: 5, shift: 6 });
                return false;
            }*/
            if(data.field.enName == data.field.transactionName){
                layer.msg("货币与法币不能相同", { icon: 5, shift: 6 });
                return false;
            }
            layer.confirm('确认要提交吗？', {
                btn : [ '确定', '取消' ]//按钮
            }, function(index) {
                layer.close(index);
                $.ajax({
                    type : "post",
                    url : "/manage/trading/updateTransaction",
                    dataType : "json",
                    data :data.field,
                    success : function(result) {
                        if (result.code >= 0) {
                            location.href = "/manage/trading/trapage";
                        }else{
                            layer.msg(result.msg, { icon: 7, shift: 6 });
                        }
                    }
                });
            });
            return false;
        });
    })
</script>
</body>
</html>